<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/24
 * Time: 17:44
 */

namespace app\statistical\controller;


use cmf\controller\AdminBaseController;
use think\Db;

class PreStudentController extends AdminBaseController
{
    /**
     * @return mixed
     */
    public  function index()
    {

        $param=$this->request->param();

        $where = [
            'c.shop_id' => ['=', $this->admin_shop_id],
            'c.delete_time' => ['eq', 0]
        ];
        if (!empty($param['course_id'])) {
            //课程名称
            $where['co.id'] =($param['course_id']) ;
        }
        if (!empty($param['school_id']) && intval($param['school_id']) != 0) {
            //校区
            $where['c.school_id'] = intval($param['school_id']);
        }
        if (!empty($param['class_id'])) {
            //班级
            $where['c.id']= $param['class_id'];

        }

        /*
          * 学校
          */
        $school_data=Db::name('school')
            ->where('shop_id', '=', $this->admin_shop_id)//多店铺
            ->where('delete_time', '=', 0)//未删除
            ->where('is_school', '=', 0)//1:地区 0:学校
            ->select();


        /*
         * 课程分类
         */
        $course_data=Db::name('course')
            ->where('shop_id', '=', $this->admin_shop_id)//多店铺
            ->where('delete_time', '=', 0)//未删除
            ->select();



        //预选家长的人数
           $data_all=Db::name('primary_parent')->where(['delete_time'=>0])
               ->select()->count();
            //通过预选课报名的人数
            $data_tui=Db::name('class_student')->where(['student_status'=>5])
                ->select()->count();



        $tui = number_format($data_tui/$data_all,4)*100..'%';


        $this->assign('data_all',json_encode($data_all));
        $this->assign('data_tui',json_encode($data_tui));

        $this->assign('tui', $tui);
        $this->assign('school_data',$school_data);
        $this->assign('course_data',$course_data);
        $this->assign('param',$param);
        return $this->fetch();

    }
}